﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Editor.TypeSelector;

using DslModeling = global::Microsoft.VisualStudio.Modeling;

namespace devtm.AutoMapper
{
    public class PrimitiveTypeProvider : ITypeProvider
    {
        List<Type> lst = new List<Type>();

        public PrimitiveTypeProvider()
        {
            SourceTypes.Source.Add(this);
            lst.Add(typeof(bool));
            lst.Add(typeof(Byte));
            lst.Add(typeof(char));
            lst.Add(typeof(DateTime));
            lst.Add(typeof(Double));
            lst.Add(typeof(Guid));
            lst.Add(typeof(Int16));
            lst.Add(typeof(Int32));
            lst.Add(typeof(Int64));
            lst.Add(typeof(SByte));
            lst.Add(typeof(Single));
            lst.Add(typeof(String));
            lst.Add(typeof(Type));
            lst.Add(typeof(UInt16));
            lst.Add(typeof(UInt32));
            lst.Add(typeof(UInt64));
            lst.Add(typeof(TimeSpan));
        }

        public IEnumerable<Type> GetTypes(DslModeling.Store store, HashSet<String> namespaces)
        {
            foreach (Type type in lst)
                yield return type;
        }

        public IEnumerable<Type> GetTypes(DslModeling.Store store, HashSet<String> namespaces, Func<Type, bool> filter)
        {

            foreach (Type type in lst)
                if (filter(type))
                    yield return type;

        }

        
        #region Disposable

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~PrimitiveTypeProvider()
        {
            Dispose(false);
        }

        // The bulk of the clean-up code is implemented in Dispose(bool)
        protected virtual void Dispose(bool disposing)
        {

            if (disposing)
            {
                // free managed resources
            
            }

            SourceTypes.Source.Remove(this);

        }

        #endregion

    }
}
